#include <memory>
#include <iostream>
class B; // 前置声明

class A {
public:
    std::shared_ptr<B> bPtr;
    ~A() {
        std::cout << "A deleted" << std::endl;
    }
};

class B {
public:
    std::weak_ptr<A> aPtr;  // 使用weak_ptr替代shared_ptr
    ~B() {
        std::cout << "B deleted" << std::endl;
    }
};

void test() {
    auto a = std::make_shared<A>();
    auto b = std::make_shared<B>();
    a->bPtr = b;
    b->aPtr = a;
}
int main() {
    test();
    return 0;
}